<?php
/******************************************************
v4 - Management Framework
Copyright (C) 2008  Gary Taylor, gMerc Incorporation
http://www.gmerc.com/v4/

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

gary@gmerc.com
******************************************************/
class editpersonnel {
  function loaddata() {
    global $masterclass;

    $masterclass->loadmodule('personnel');

    $masterclass->loadjavascript('',$masterclass->mainconfig['v4rootdir'].'include/suckertreemenu.inc.js');
    
    $masterclass->websiteconfig['title']=$masterclass->allclasses['personnel']->fetch_personnelname($masterclass->sitevars['personnelid']);
    
    $masterclass->site['postfields'][] = array(
      'table'=>'personnel',
      'trackingid'=>'personnelid',
      'fields'=>array(
        'active'=>'personnel_active',

        'first'=>'personnel_first',
        'last'=>'personnel_last',
        'spouse'=>'personnel_spouse',

        'address'=>'personnel_address',
        'apt'=>'personnel_apt',
        'city'=>'personnel_city',
        'state'=>'personnel_state',
        'zip'=>'personnel_zip',

        'www'=>'personnel_www',
        'emaila'=>'personnel_emaila',
        'emailb'=>'personnel_emailb',
        'dayphone'=>'personnel_dayphone',
        'dayphoneext'=>'personnel_dayphoneext',
        'nightphone'=>'personnel_nightphone',
        'nightphoneext'=>'personnel_nightphoneext',
        'otherphonea'=>'personnel_otherphonea',
        'otherphoneaext'=>'personnel_otherphoneaext',
        'otherphoneb'=>'personnel_otherphoneb',
        'otherphonebext'=>'personnel_otherphonebext',
        'pager'=>'personnel_pager',
        'pagertype'=>'personnel_pagertype',

        'location'=>'personnel_location',
        'team'=>'personnel_team',
        'subteam'=>'personnel_subteam',

        'title'=>'personnel_title',
        'department'=>'personnel_department',
        'companyext'=>'personnel_companyext',
        'companyemail'=>'personnel_companyemail'
      )
    );
    
  return;
  }
  function savedata() {
    global $masterclass;

    foreach ($masterclass->sitevars['post_action'] as $postaction) {
      switch ($postaction) {
       case 'personnel_save':
        
        $masterclass->site['forward']='window.close();';
        
        if (isset($masterclass->sitevars['personnelid']) && $masterclass->sitevars['personnelid']>0) {
          $arrlogininfo = $masterclass->fetch_login('personnelid',$masterclass->sitevars['personnelid']);
          print_r($arrlogininfo);
          if ($masterclass->sitevars['personnel_password']!=$arrlogininfo['login_pass']) { $updatelogin='1'; }
          if ($masterclass->sitevars['personnel_username']!=$arrlogininfo['login_user']) {
            if ($masterclass->checkloginuser($masterclass->sitevars['personnel_username'])==false) { $updatelogin='1'; } else { $masterclass->site['forward']=''; }
          }
        } else {
          if ($masterclass->checkloginuser($masterclass->sitevars['personnel_username'])==false) { $updatelogin='1'; } else { $masterclass->site['forward']=''; }
        }

        $masterclass->savedata();
        
        if ($updatelogin=='1') {
          $strwhere=sprintf(" `trackingvar`='personnelid' AND `trackingid`=%d ",$masterclass->allclasses['mysql_functions']->formatmysqldbl($masterclass->sitevars['personnelid']));
          $dbinfo = array(
            'table'=>'logins',
            'strwhere'=>$strwhere
          );
          $masterclass->db_delete($dbinfo);
    
          $dbinfo = array(
            'table'=>'logins',
            'fields'=>array(
              'username'=>'personnel_username',
              'password'=>'personnel_password',
              'trackingid'=>'personnelid'
            ),
            'static'=>array(
              'active'=>'1',
              'trackingvar'=>'personnelid'
            )
          );
          $masterclass->db_insert($dbinfo);
        }
       break;
       case 'personnel_delete':
       
        $deletefields=array();
        if ($masterclass->sitevars['personnelid']>1) {
          $strwhere=sprintf(" `id`=%d ",$masterclass->allclasses['mysql_functions']->formatmysqldbl($masterclass->sitevars['personnelid']));
          $deletefields[] = array(
            'table'=>'personnel',
            'strwhere'=>$strwhere
          );
        }  
        $masterclass->deletedata($deletefields);
        
        $masterclass->site['forward']='window.close();';
       break;
      }
    }    
  return;
  }

  function display() {
  global $masterclass;

  if (isset($masterclass->sitevars['personnelid']) && $masterclass->sitevars['personnelid']>0) {
    $arrlogininfo = $masterclass->fetch_login('personnelid',$masterclass->sitevars['personnelid']);
    $masterclass->sitevars['personnel_username']=$arrlogininfo['login_user'];
    $masterclass->sitevars['personnel_password']=$arrlogininfo['login_pass'];
  }
    
?>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top">
    <td>
<?php
  echo $masterclass->allclasses['websites']->sitebox_pageheader($masterclass->sitevars['personnel_first'].' '.$masterclass->sitevars['personnel_last'].' ['.$masterclass->sitevars['personnelid'].']','');
?>
  </td>
  </tr>
</table>
<?php
$nav='';
$nav.='<div class="sitebox_navigation" style="width:100%;">';
$nav.='<ul id="sitebox_navmenu">';
$nav.='<li OnClick="jsshowloadingscreen();add_post_action(\'personnel_save\');frm.submit();"><a>Save</a></li>';
//$nav.='<li OnClick="openwindow(\''.$masterclass->mainconfig['dir'].$masterclass->mainconfig['htmldirectory'].'invoices/makepayment_default.php?'.$masterclass->trackingvar_query().'\',\'_blank\',\'760\',\'480\');"><a>New Payment</a></li>';
if (isset($masterclass->sitevars['personnelid']) && $masterclass->sitevars['personnelid']>1) {
  $nav.='<li OnClick="if (confirm(\'DELETE\n\nAre You Sure?\')) { jsshowloadingscreen();add_post_action(\'personnel_delete\');frm.submit(); }"><a>Delete</a></li>';
}
$nav.='<li OnClick="window.close();"><a>Close</a></li>';
$nav.='</ul>';
$nav.='<br style="clear: left;" />';
$nav.='</div>';
echo $nav;
?>
<table width="100%" cellpadding="2" cellspacing="5" border="0">
  <tr valign="top">
  <td width="50%">
<?php
/* Start Window */
  echo $masterclass->allclasses['websites']->sitebox_start('100%');
  echo $masterclass->allclasses['websites']->sitebox_headline('Personal Information','');
?>
<table width="100%" align="center" cellpadding="0" cellspacing="1" class="sitebox_content">
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;"><nobr>First Name:&nbsp;</nobr></td>
    <td width="90%"><?php echo $masterclass->allclasses['websites']->disp_inputtext('personnel_first','35%');?>&nbsp;&nbsp;Spouse&nbsp;<?php echo $masterclass->allclasses['websites']->disp_inputtext('personnel_spouse','35%');?></td>
  </tr>
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;"><nobr>Last Name:&nbsp;</nobr></td>
    <td width="90%"><?php echo $masterclass->allclasses['websites']->disp_inputtext('personnel_last');?></td>
  </tr>
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;">E-Mail:&nbsp;</td>
    <td width="90%"><nobr><?php echo $masterclass->allclasses['websites']->disp_inputtext('personnel_emaila','55%');?>&nbsp;<input type="button" value="email" OnClick=""></nobr></td>
  </tr>
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;">E-Mail:&nbsp;</td>
    <td width="90%"><nobr><?php echo $masterclass->allclasses['websites']->disp_inputtext('personnel_emailb','55%');?>&nbsp;<input type="button" value="email" OnClick=""></nobr></td>
  </tr>
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;"><nobr>Day Phone:&nbsp;</nobr></td>
    <td width="90%"><nobr><?php echo $masterclass->allclasses['websites']->disp_inputtext('personnel_dayphone','65%');?>&nbsp;<?php echo $masterclass->allclasses['websites']->disp_inputtext('personnel_dayphoneext','15%');?></nobr></td>
  </tr>
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;"><nobr>Night Phone:&nbsp;</nobr></td>
    <td width="90%"><nobr><?php echo $masterclass->allclasses['websites']->disp_inputtext('personnel_nightphone','65%');?>&nbsp;<?php echo $masterclass->allclasses['websites']->disp_inputtext('personnel_nightphoneext','15%');?></nobr></td>
  </tr>
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;"><nobr>1st Cell:&nbsp;</nobr></td>
    <td width="90%"><nobr><?php echo $masterclass->allclasses['websites']->disp_inputtext('personnel_otherphonea','65%');?>&nbsp;<?php echo $masterclass->allclasses['websites']->disp_inputtext('personnel_otherphoneaext','15%');?></nobr></td>
  </tr>
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;"><nobr>2nd Cell:&nbsp;</nobr></td>
    <td width="90%"><nobr><?php echo $masterclass->allclasses['websites']->disp_inputtext('personnel_otherphoneb','65%');?>&nbsp;<?php echo $masterclass->allclasses['websites']->disp_inputtext('personnel_otherphonebext','15%');?></nobr></td>
  </tr>
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;">Address:&nbsp;</td>
    <td width="90%"><?php echo $masterclass->allclasses['websites']->disp_inputtext('personnel_address');?></td>
  </tr>
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;">Apt/Bldg #:&nbsp;</td>
    <td width="90%"><?php echo $masterclass->allclasses['websites']->disp_inputtext('personnel_apt');?></td>
  </tr>
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;">City:&nbsp;</td>
    <td width="90%"><?php echo $masterclass->allclasses['websites']->disp_inputtext('personnel_city');?></td>
  </tr>
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;">State:&nbsp;</td>
    <td width="90%"><?php echo $masterclass->allclasses['websites']->disp_inputtext('personnel_state','20%');?>&nbsp;&nbsp;&nbsp;Zip:&nbsp;&nbsp;</span><?php echo $masterclass->allclasses['websites']->disp_inputtext('personnel_zip','55%');?></nobr></td>
  </tr>
</table>
<?php
  echo $masterclass->allclasses['websites']->sitebox_end();
/* End Window */
?>
</td><td width="50%">
<?php
/* Start Window */
  echo $masterclass->allclasses['websites']->sitebox_start('100%');
  echo $masterclass->allclasses['websites']->sitebox_headline('Intranet Information','');
?>
<table width="100%" align="center" cellpadding="0" cellspacing="1" class="sitebox_content">
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;">Username:&nbsp;</td>
    <td width="90%"><nobr><?php echo $masterclass->allclasses['websites']->disp_inputtext('personnel_username','','12');?>&nbsp;&nbsp;Pass:&nbsp;<?php echo $masterclass->allclasses['websites']->disp_inputtext('personnel_password','35%','12');?></nobr></td>
  </tr>
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;"><nobr>E-Mail:&nbsp;</nobr></td>
    <td width="90%"><?php echo $masterclass->allclasses['websites']->disp_inputtext('personnel_companyemail','','20');?></td>
  </tr>
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;">Location:&nbsp;</td>
    <td width="90%"><nobr><?php
$options=array();
$options[]=array('0','Default Location');
echo $masterclass->allclasses['websites']->disp_select($options,'personnel_location',$masterclass->sitevars['personnel_location'],'45%');
?>&nbsp;&nbsp;Company Ext:&nbsp;<?php echo $masterclass->allclasses['websites']->disp_inputtext('personnel_companyext','15%');?></nobr></td>
  </tr>
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;">Pager:&nbsp;</td>
    <td width="90%"><?php echo $masterclass->allclasses['websites']->disp_inputtext('personnel_pager','','10');?>&nbsp;&nbsp;Carrier:&nbsp;<?php
$options=array();
$options[]=array('verizon','Verizon');
$options[]=array('sprintpcs','Sprint PCS');
$options[]=array('cingular','Cingular');
$options[]=array('nextel','Sprint Nextel');
$options[]=array('alltel','Alltel');
$options[]=array('tmobile','T-Mobile');
$options[]=array('att','AT&T');
$options[]=array('virgin','Virgin Mobile');
echo $masterclass->allclasses['websites']->disp_select($options,'personnel_pagertype',$masterclass->sitevars['personnel_pagertype'],'35%');?></nobr></td>
  </tr>
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;">Title:&nbsp;</td>
    <td width="90%"><?php echo $masterclass->allclasses['websites']->disp_inputtext('personnel_title','85%');?></td>
  </tr>
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;">Department:&nbsp;</td>
    <td width="90%"><?php
$options=array();
$options[]=array('0','No Department');
echo $masterclass->allclasses['websites']->disp_select($options,'personnel_department',$masterclass->sitevars['personnel_department'],'85%');?></nobr></td>
  </tr>
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;">Team:&nbsp;</td>
    <td width="90%"><?php
$options=array();
$options[]=array('0','No Team');
echo $masterclass->allclasses['websites']->disp_select($options,'personnel_team',$masterclass->sitevars['personnel_team'],'85%');?></td>
  </tr>
  <tr valign="bottom">
    <td valign="middle" style="padding-left:2px;text-align:right;">Subteam:&nbsp;</td>
    <td width="90%"><?php
$options=array();
$options[]=array('0','No SubTeam');
echo $masterclass->allclasses['websites']->disp_select($options,'personnel_subteam',$masterclass->sitevars['personnel_subteam'],'85%');?></td>
  </tr>
</table>
<?php
  echo $masterclass->allclasses['websites']->sitebox_end();
/* End Window */
?>
</td></tr></table>
<?php

  return;
  }
}
?>